package com.hwadee.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hwadee.springboot.entity.Parent;
import com.hwadee.springboot.entity.studnrtEntity.StudnetTestInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface ParentConMapper{
    @Select("SELECT\n" +
            "    s.StudentID AS id,\n" +
            "    s.StudentName AS studentName,\n" +
            "    g.Subject AS testName,\n" +
            "    CASE\n" +
            "        WHEN g.Score IS NULL THEN '未开始'\n" +
            "        WHEN g.Score = '' THEN '进行中'\n" +
            "        ELSE '完成'\n" +
            "        END AS status,\n" +
            "    g.Score AS score,\n" +
            "    g.Semester AS testDate,\n" +
            "    '月考' AS testType,\n" +
            "    p.ParentID AS parentid,\n" +
            "    p.ParentName AS parentname,\n" +
            "    p.Gender AS gender,\n" +
            "    p.BirthDate AS birthdate,\n" +
            "    p.ContactPhone AS contactphone,\n" +
            "    p.Email AS email,\n" +
            "    p.Address AS address,\n" +
            "    p.Relationship AS relationship\n" +
            "FROM student s\n" +
            "         LEFT JOIN grade g ON s.StudentID = g.StudentID\n" +
            "         LEFT JOIN parent p ON s.ParentID = p.ParentID")
    @Results({
            @Result(property = "parent.parentid", column = "parentID"),
            @Result(property = "parent.parentname", column = "parentName"),
            @Result(property = "parent.gender", column = "Gender"),
            @Result(property = "parent.birthdate", column = "BirthDate"),
            @Result(property = "parent.contactphone", column = "ContactPhone"),
            @Result(property = "parent.email", column = "Email"),
            @Result(property = "parent.address", column = "Address"),
            @Result(property = "parent.relationship", column = "Relationship")
    })
    List<StudnetTestInfo> selectStudnetTestInfo();

}
